class VegasVideoTime
  attr_accessor  :h, :m, :s, :l
  def self.new h0=0, m0=0, s0=0, l0=0
    vvm_time = super()
    vvm_time.h = h0; vvm_time.m = m0; vvm_time.s = s0; vvm_time.l = l0
    vvm_time
  end

  def self.nl l
    h = l / 108000
    m = l % 108000 / 1800
    s = l % 108000 % 1800 / 30
    l0 = l % 108000 % 1800 % 30
    self.new h, m, s, l0
  end

  def self.ns s
    self.nl s.to_i * 30
  end
  
  def to_s
    "#{@h.to_s}:#{@m.to_s}:#{@s.to_s}:#{@l.to_s}"
  end

  def to_i
    @h * 108000 + @m * 1800 + @s * 30 + @l
  end
  
  def add vvm_time
    l = self.to_i + (vvm_time.class == VegasVideoTime ? vvm_time.to_i : vvm_time.to_i * 30)
    @h = l / 108000
    @m = l % 108000 / 1800
    @s = l % 108000 % 1800 / 30
    @l = l % 108000 % 1800 % 30
    self
  end
  
  def add_s second, li = 0
    add VegasVideoTime.nl(second *30 + li)
  end

  def add_l li
    add VegasVideoTime.nl(li)
  end
  
  def less vvm_time
    l = self.to_i - (vvm_time.class == VegasVideoTime ? vvm_time.to_i : vvm_time.to_i * 30)
    @h = l / 108000
    @m = l % 108000 / 1800
    @s = l % 108000 % 1800 / 30
    @l = l % 108000 % 1800 % 30
    self
  end
  
  def - vvm_time
    tmp = self.clone
    tmp.less vvm_time
    tmp
  end
  
  def + vvm_time
    tmp = self.clone
    tmp.add vvm_time
    tmp
  end
  
  def self.zero
    self.new.to_s
  end
end